//
//  BAShopCell.m
//  YunFu
//
//  Created by Bager on 2018/9/4.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "BAShopCell.h"

@implementation BAShopCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setViews];
    }
    
    return self;
}

- (void)setViews
{
    [self addSubview:self.img];
    [self addSubview:self.name];
    [self addSubview:self.starView];
    [self addSubview:self.type];
    [self addSubview:self.address];
    [self addSubview:self.price];
}

- (UIImageView *)img
{
    if (!_img)
    {
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(kPublicMargin, 5, 110, 90)];
        _img.contentMode = UIViewContentModeScaleAspectFill;
        _img.layer.masksToBounds = YES;
        _img.layer.cornerRadius = 4;
        [_img setImage:[UIImage imageNamed:@"yf2-mddh1-15"]];
    }
    return _img;
}

- (UILabel *)name
{
    if (!_name)
    {
        _name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.img.frame) + 10, 5, kScreenWidth - kPublicMargin - CGRectGetMaxX(self.img.frame) - 10, 30)];
        _name.font = [UIFont systemFontOfSize:14];
        _name.adjustsFontSizeToFitWidth = YES;
        _name.text = @"艳遇锅包肉plus";
    }
    return _name;
}

- (XHStarRateView *)starView
{
    if (!_starView)
    {
        _starView = [[XHStarRateView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.name.frame), 70, 20)];
        _starView.currentScore = 4.3;
    }
    return _starView;
}

- (UILabel *)type
{
    if (!_type)
    {
        _type = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), 55, 100, 20)];
        _type.font = [UIFont systemFontOfSize:12];
        _type.textColor = [UIColor lightGrayColor];
        _type.text = @"中餐厅 1.6km";
    }
    return _type;
}

- (UILabel *)address
{
    if (!_address)
    {
        _address = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.type.frame), 75, CGRectGetWidth(self.name.frame), 20)];
        _address.font = [UIFont systemFontOfSize:10];
        _address.textColor = [UIColor lightGrayColor];
        _address.adjustsFontSizeToFitWidth = YES;
        _address.text = @"地址：珲春市新安路1235号";
    }
    return _address;
}

- (UILabel *)price
{
    if (!_price)
    {
        _price = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 120 - kPublicMargin, CGRectGetMinY(self.type.frame), 120, 20)];
        _price.font = [UIFont systemFontOfSize:12];
        _price.textColor = [UIColor lightGrayColor];
        _price.adjustsFontSizeToFitWidth = YES;
        _price.textAlignment = NSTextAlignmentRight;
        _price.text = @"人均：¥66";
        _price.attributedText = [self convertColorString:_price.text];
    }
    return _price;
}

- (NSMutableAttributedString *)convertColorString:(NSString *)str
{
    NSMutableAttributedString *strnew = [[NSMutableAttributedString alloc]initWithString:str];
    [strnew addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3, str.length - 3)];
    return strnew;
}

@end
